
var url = java.lang.System["getProperty"]('document.url');
var path = java.lang.System["getProperty"]('document.path');
var query = java.lang.System["getProperty"]('query.string');
var logger =  java.util.logging.Logger.getLogger("JS.engin");

function log(log){
	logger.info(log);
}

var logs = [];

function report(message){
	logs.push(message);
}

HTMLLint.prototype.populate = function() {
      for(var i = 0 ,logs = this.log ,len = logs.length; i < len ; i++)
      	log(logs[i]);
};

function parserURL(url,options){
	return parserHTML(readUrl(url),options);
}

function parserHTML(html,options){
	try {
    var lint = options.lint,
          minifiedValue = minify(html, options, report),
          diff = html.length - minifiedValue.length,
          savings = html.length ? ((100 * diff) / html.length).toFixed(2) : 0,
          info = path ? (path + '\t' + url + '\t' + query + '\t') : '';
          log(info  + html.length + 
          '\t' + minifiedValue.length + 
          '\t' + diff + ' (' + savings + '%)');
          
         lint && lint.populate();
	    return minifiedValue;
    }
    catch(err) {
      //logger.severe("JS enginer Error:" + err + "JS Error:" + logs.join("<br>"));
      //throw new Error("<br>JS Error:" + logs.join("<br>"));
      throw err;
    }
}
